import 'package:flutter/material.dart';
import 'package:flutter_demo/page/base_page_state.dart';
import 'package:flutter_demo/page/home/home_page.dart';
import 'package:flutter_demo/page/mall/mall_page.dart';
import 'package:flutter_demo/page/news/news_page.dart';
import 'package:flutter_demo/page/user/user_page.dart';

class MainPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return MainPageState();
  }
}

class MainPageState extends BasePageState<MainPage> {
  int _selectedIndex = 0;
//  Map<int, Widget> _pages = Map();
  List<Widget> _pages = [HomePage(), MallPage(), NewsPage(), UserPage()];

  @override
  void initState() {
    super.initState();
    appBarController.visible = false;
  }
  @override
  Widget buildBody(BuildContext context) {
    return IndexedStack(
        index:_selectedIndex,
        children:_pages
    );
  }

  @override
  Widget buildBottomNavigationBar(BuildContext context) {
    return BottomNavigationBar(
      items: <BottomNavigationBarItem>[
        BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('首页')),
        BottomNavigationBarItem(icon: Icon(Icons.business), title: Text('商城')),
        BottomNavigationBarItem(icon: Icon(Icons.school), title: Text('新闻')),
        BottomNavigationBarItem(icon: Icon(Icons.person), title: Text('个人')),
      ],
      type: BottomNavigationBarType.fixed,
      currentIndex: _selectedIndex,
      onTap: _handleItemClick,
    );
  }

  _handleItemClick(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }
}